<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        aabccd统计每个字符出现的次数，去掉重复的字符，使结果显示 abcd
    </div>
    <!-- <script>
        function CountChar ( str , a ) {
            var count = 0 ;
            for ( var i = 0 ; i < str.length ; i ++ ) {
                if ( str[i] == a ) {
                    count ++ ;
                }
            }
            var res = "含有字符" + a + count + "个" ; 
            return res ; 
        }
        function noRepeatChar( str ) {
            var arr = str.split("");
            var set = new Set(arr);
            return Array.from(set).join("");
        }
        var str = "aabccd" ;
        var str2 =  noRepeatChar(str); 
        console.log(str2);
        for ( var i = 0 ; i < str2.length ; i ++ ) {
            CountChar( str , str2[i] );
            console.log(CountChar( str , str2[i] ));
        }
    </script> -->
    <!-- 改进版 -->
    <script>
        function CountChar ( str ) {
            var obj = {} ; 
            for ( var i = 0 ; i < str.length ; i ++ ) {
                if ( obj[i] != undefined ) {
                    obj[i] = 1 ; 
                } else {
                    obj[i] ++ ;
                }
            }
            return obj ; 
        }
        // 相当于每个对象键名存储的是字符串的不重复字母，键值存放的是字符串重复的次数
    </script>
</body>
</html>